import subprocess
import os
from natsort import ns, natsorted

path = r"V:\FFOutput"

included_extensions = ['mp4']

file_names = [fn for fn in os.listdir(path)
              if any(fn.endswith(ext) for ext in included_extensions)]

files = natsorted(file_names,alg=ns.PATH)
mp4s = files
print(file_names)

# mp4s = "o050.mp4,o049.mp4".split(',')
out_dir = path
out_file = "temp.mp4"
temp_txt = "temp.txt"
temp_txt_file = out_dir + "/" + temp_txt

m_command = "ffmpeg -f concat -i " + temp_txt + " -c copy " + out_file
#
for mp4 in mp4s:
    with open(temp_txt_file , "a") as file:
        file.write("file '" + mp4 + "'\n")
#
os.chdir(out_dir)
subprocess.run(m_command, shell=True, check=True)
#
if (os.path.exists(temp_txt_file)):
    os.remove(temp_txt_file)